package leetcode.link;

public class Test19 {
    public static void main(String[] args) {

    }
    //0- 1,2,3,4

    public static ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode virtual = new ListNode(0,head);
        ListNode fast = virtual,slow = virtual,current  = virtual;
        for (int i = 1; i <= n ; i++) {
            fast = fast.next;
        }
        while (fast.next != null){
                fast = fast.next;
                slow = slow.next;
        }
        slow.next = slow.next.next;
        return virtual.next;
    }
}
